﻿using RTW.DAL;
using RTW.OA.Models;
using System.Collections.Generic;
using System.Linq;

namespace RTW.OA.Areas.Common.Servers
{
    public class DocumentReceiveServers
    {
        private readonly IRepository<official_document_receive> officialDocumentReceiveRepository;

        public DocumentReceiveServers()
        {
            officialDocumentReceiveRepository = new DapperRepository<official_document_receive>();
        }

        public List<official_document_receive> GetData()
        {
            var datas = officialDocumentReceiveRepository.GetAllEnumerable();
            return datas.ToList();
        }

        public IEnumerable<official_document_receive> GetData(int docId)
        {
            //var datas = officialDocumentReceiveRepository.GetAllEnumerable();
            //return datas.Where(i => i.DOC_ID == docId).ToList();
            string sql = string.Format("SELECT * FROM[OADB].[dbo].[official_document_receive] WHERE DOC_ID = {0}",docId);
            return officialDocumentReceiveRepository.SqlWithParams(sql);
        }

        public IEnumerable<official_document_receive> GetDataByUserNO(string userNO)
        {
            string sql = string.Format("SELECT * FROM [OADB].[dbo].[official_document_receive] WHERE [RECEIVER_USER_NO]='{0}' ORDER BY CREATE_TIME DESC", userNO);
            return officialDocumentReceiveRepository.SqlWithParams(sql);
        }

        public official_document_receive GetModelById(int id)
        {
            return officialDocumentReceiveRepository.GetById(id);
        }
		
        internal void Add(official_document_receive model)
        {
            officialDocumentReceiveRepository.Insert(model);
        }

        internal void Update(official_document_receive model)
        {
            officialDocumentReceiveRepository.Update(model);
        }

		internal void Del(string id)
        {
            officialDocumentReceiveRepository.DeleteByIds(id);
        }

    }
}